package com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RequestPass;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.req.SmsEnrollmentManagementStudentInfoBatchReq;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.req.SmsEnrollmentManagementStudentInfoExportReq;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.req.SmsEnrollmentManagementStudentInfoReq;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.service.SmsEnrollmentManagementStudentInfoService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.Future;

/**
 * <p>
 * 招生管理学生信息 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/enrollment/student")
@SecretBody
public class SmsEnrollmentManagementStudentInfoController {
    @Resource
    private SmsEnrollmentManagementStudentInfoService smsEnrollmentManagementStudentInfoService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @PostMapping("/add")
    @ApiModelProperty(value = "学生预报名")
    @RequestPass
    public ResponseResult addEnrollmentManagementStudentInfo(@RequestBody SmsEnrollmentManagementStudentInfoReq studentInfoReq){
        return smsEnrollmentManagementStudentInfoService.addEnrollmentManagementStudentInfo(studentInfoReq);
    }

    @PostMapping("/batch")
    @ApiModelProperty(value = "学生预报名信息批量导入")
    public ResponseResult batchEnrollmentManagementStudentInfo(@RequestBody SmsEnrollmentManagementStudentInfoBatchReq studentInfoReq, HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try{
            Future<ResponseResult> future = smsEnrollmentManagementStudentInfoService.batchEnrollmentManagementStudentInfo(studentInfoReq,user_id);
            while (true){
                if (future.isDone()){
                    commonCodeEnum = future.get();
                    break;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    @PostMapping("/delete")
    @ApiModelProperty(value = "删除学生预报名信息")
    public ResponseResult deleteEnrollmentManagementStudentInfo(@RequestBody SmsEnrollmentManagementStudentInfoReq studentInfoReq){
        return smsEnrollmentManagementStudentInfoService.deleteEnrollmentManagementStudentInfo(studentInfoReq);
    }

    @PostMapping("/update")
    @ApiModelProperty(value = "修改学生预报名信息")
    public ResponseResult updateEnrollmentManagementStudentInfo(@RequestBody SmsEnrollmentManagementStudentInfoReq studentInfoReq){
        return smsEnrollmentManagementStudentInfoService.updateEnrollmentManagementStudentInfo(studentInfoReq);
    }

    @GetMapping("/list")
    @ApiModelProperty(value = "获取学生预报名列表")
    public ResponseResult getEnrollmentManagementStudentInfoList(@RequestParam(value = "searchStr",required = false) String searchStr,
                                                                 @RequestParam(value = "signMethod",required = false) Integer signMethod,
                                                                 @RequestParam(value = "enrollmentTeacherId",required = false) String enrollmentTeacherId,
                                                                 @RequestParam(value = "collegeId",required = false) String collegeId,
                                                                 @RequestParam(value = "majorId",required = false) String majorId,
                                                                 @RequestParam(value = "returnVisitTeacherId",required = false)String returnVisitTeacherId,
                                                                 @RequestParam(value = "sex",required = false)String sex,
                                                                 @RequestParam(value = "isCancel",required = false)Integer isCancel,
                                                                 @RequestParam(value = "taskId",required = false)String taskId,
                                                                 @RequestParam(value = "enrollmentType")Integer enrollmentType,
                                                                 @RequestParam(value = "singleOrUnifiedRecruitment",required = false)Integer singleOrUnifiedRecruitment,
                                                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
                                                                 ){
        return smsEnrollmentManagementStudentInfoService.getEnrollmentManagementStudentInfoList(searchStr, signMethod, enrollmentTeacherId, collegeId,
                majorId, returnVisitTeacherId, sex,isCancel,taskId,enrollmentType,singleOrUnifiedRecruitment,pageNum, pageSize);
    }

    @GetMapping("/detail")
    @ApiModelProperty(value = "获取学生预报名详情")
    public ResponseResult getEnrollmentManagementStudentInfoList(@RequestParam(value = "id") String id){
        return smsEnrollmentManagementStudentInfoService.getEnrollmentManagementStudentInfoDetail(id);
    }

    @PostMapping("/cancel")
    @ApiModelProperty(value = "作废学生信息")
    public ResponseResult cancelStudentInfo(@RequestBody SmsEnrollmentManagementStudentInfoReq studentInfoReq){
        return smsEnrollmentManagementStudentInfoService.cancelStudentInfo(studentInfoReq);
    }

    @PostMapping("/export")
    @ApiModelProperty(value = "学生信息导出")
    public ResponseResult exportEnrollmentManagementStudentInfoList(@RequestBody SmsEnrollmentManagementStudentInfoExportReq req, HttpServletResponse response) {
        ResponseResult responseResult;
        try{
            Future<ResponseResult> future = smsEnrollmentManagementStudentInfoService.exportEnrollmentManagementStudentInfoList(req, response);
            while (true){
                if (future.isDone()){
                    break;
                }
            }
            responseResult = future.get();
        }catch (Exception e){
            e.printStackTrace();
            responseResult = CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return responseResult;
    }

}

